package main;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

import mvc.AbstractView;
import mvc.IController;


public class ConsoleInterpreterSingleton implements IViewEventDispatcher
{	
	private ConsoleInterpreterSingleton()
	{
	}
	
	public void run() throws IOException
	{
		BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
	    String str;
	    while((str = in.readLine()) != null && !str.equals("q"))
	    {
	    	itsActiveView.onInputString(str);
	    }
	}

	@Override
	public void pipeEventsTo(AbstractView view)
	{
		itsActiveView = view;
		
	}
	
	/*
	 * Singleton implementation
	 */
	public static ConsoleInterpreterSingleton getInstance()
	{
		return instance;
	}
	
	private static final ConsoleInterpreterSingleton instance = new ConsoleInterpreterSingleton();
	private AbstractView itsActiveView;

}
